package com.wfc.servlet.cook;

import com.wfc.entity.Cook;
import com.wfc.service.CookService;
import com.wfc.service.serviceImpl.CookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/cook")
public class CookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        //根据用户名查找用户菜品
        CookService cookService = new CookServiceImpl();
        List<Cook> cookList = cookService.selectByuname(username);
        HttpSession session = req.getSession();
        for(Cook cook : cookList){
            //菜谱的制作图片
            String cooking = cook.getCooking();
            String[] imgs = cooking.split("&");
            session.setAttribute("cookingimgs",imgs);
            //菜谱的主食
            String mainfood = cook.getMainfood();
            String[] mainfoods = mainfood.split("&");
            session.setAttribute("mainfoods",mainfoods);
            //菜谱的辅食
            String fufood = cook.getFufood();
            String[] fufoods = fufood.split("&");
            session.setAttribute("fufoods",fufoods);
            //菜谱的调料
            String tiaofood = cook.getTiaofood();
            String[] tiaofoods = tiaofood.split("&");
            session.setAttribute("tiaofoods",tiaofoods);
            //菜谱的 酸辣。。。。
            String process = cook.getProcess();
            String[] processs = process.split("&");
            session.setAttribute("processs",processs);
            //菜谱的制作步骤
            String cookText = cook.getCooktext();
            String[] cookTexts = cookText.split("&");
            session.setAttribute("cookTexts",cookTexts);
        }
    }
}
